function Img() {
  
  this.loadingScreenAssets = {};
  this.loadingScreenLoadedAssets = 0;
  
  this.assets = {};
  this.loadedAssets = 0;
  
  this.percentageLoaded = 0;
  this.loaded = false;
  
  this.loadingScreenInterval;
  
  this.SOUND_LOADING_TIME_PERCENTAGE = 20;
  
  this.FAKE_LOADING_TIME = 100; // Set to 100 for development
  this.FAKE_LOADING_PERCENTAGE = 50;
  
  
  this.startLoading = function() {
    this.loadLoadingScreen();
  };
  
  
  this.loadLoadingScreen = function() {
    for(var name in resources.loadingScreenImages) {
      this.loadingScreenAssets[name] = new Image();
      this.loadingScreenAssets[name].onload = function() {
        img.reportLoadingScreenAssetLoaded();
      };
      this.loadingScreenAssets[name].src = resources.loadingScreenImages[name];
    }
  };
  

  this.reportLoadingScreenAssetLoaded = function() {
    this.loadingScreenLoadedAssets++;
    if(this.loadingScreenLoadedAssets == Object.keys(resources.loadingScreenImages).length) {
      fonts.create("Black", this.loadingScreenAssets["font"], 1900, 20, 18, 1, 4);
      img.drawLoadingScreen();
      img.loadAssets();
    }
  };
  
  
  this.loadAssets = function() {
    for(var name in resources.images) {
      this.assets[name] = new Image();
      this.assets[name].onload = function() {
        img.reportAssetLoaded();
      };
      this.assets[name].src = resources.images[name];
    }
  };
  
  
  this.reportAssetLoaded = function() {
    this.loadedAssets++;
    this.percentageLoaded += (100 - (this.FAKE_LOADING_PERCENTAGE + this.SOUND_LOADING_TIME_PERCENTAGE)) / Object.keys(resources.images).length;
    this.drawLoadingScreen();
	
	// If all images are loaded, start fake loading
    if(this.loadedAssets == Object.keys(resources.images).length) {
      this.loadingScreenInterval = window.setInterval(function() {
        img.updateLoadingScreen();
      }, 33);
    }
  };
  
  // Function for fake loading
  this.updateLoadingScreen = function() {
    if(this.percentageLoaded < (100 - this.FAKE_LOADING_PERCENTAGE)) {
      this.percentageLoaded = (100 - (this.FAKE_LOADING_PERCENTAGE + this.SOUND_LOADING_TIME_PERCENTAGE));
      this.percentageLoaded += Math.ceil(this.SOUND_LOADING_TIME_PERCENTAGE * sound.percentageLoaded / 100);

    } else {
      if(Math.ceil(this.percentageLoaded) >= 100.0) {
        window.clearInterval(this.loadingScreenInterval);
        this.loaded = true;
        this.percentageLoaded = 100.0;
      
      // Control flow is shifted to game
        window.setTimeout(function() {
          game.imageLoadingEnded();
        }, 33);
      } else {
        this.percentageLoaded += this.FAKE_LOADING_PERCENTAGE * (33 / this.FAKE_LOADING_TIME);
      }
    }
    this.drawLoadingScreen();
  };
  
  
  this.drawLoadingScreen = function() {

    // customize loading screen here

    c.drawImage(this.loadingScreenAssets["background"], 0, 0);
    c.strokeStyle = "#000";
    c.strokeRect(399.5, 359.5, 161, 5);
    c.fillStyle = "#000";
    c.fillRect(400, 360, 160 * (this.percentageLoaded / 100), 4);
    if(fonts.created("Black")) {
      var percentageText = new Text();
      percentageText.setFont("Black");
      percentageText.setAlignment(Text.CENTER);
      percentageText.setPosition(482, 367);
      percentageText.text(Math.round(this.percentageLoaded) + "%");
      percentageText.draw();
    }
  };
  
  
  this.get = function(name) {
    return this.assets[name];
  };
  
  
  this.draw = function(name, x, y) {
    c.drawImage(this.assets[name], x, y);
  };
  
  
  this.drawSprite = function(name, x, y, w, h, posX, posY) {
    c.drawImage(this.assets[name], w * posX, h * posY, w, h, x, y, w, h);
  };
  
  
  this.drawRotated = function(name, x, y, centerX, centerY, angle) {
    
    if (this.drawImageExists(name)) {
      return false;
    }
    
    c.save();
    c.translate(x, y);
    c.rotate(angle * 0.0174533);
    c.translate(-centerX, -centerY);
    c.drawImage(this.assets[name], 0, 0);
    c.restore();
  };
  
  
  this.drawRotatedSprite = function(name, x, y, w, h, posX, posY, centerX, centerY, angle) {
    
    if (this.drawImageExists(name)) {
      return false;
    }
    c.save();
    c.translate(x, y);
    c.rotate(angle * 0.0174533);
    c.translate(-centerX, -centerY);
    c.drawImage(this.assets[name], w * posX, h * posY, w, h, 0, 0, w, h);
    c.restore();
  };
  
  this.drawImageExists = function(name) {
    
    if (name in this.assets) {
      return true;
    }
    return false;
  };
    
}